package com.yj.consumer.config;

import com.alibaba.cloud.sentinel.annotation.SentinelRestTemplate;
import org.springframework.cloud.client.loadbalancer.LoadBalanced;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.client.RestTemplate;

@Configuration
public class ApplicationContextConfig {
    @Bean
    @LoadBalanced//开启RestTemplate的负载均衡，默认轮询策略
    @SentinelRestTemplate//将RestTemplate调用的远程接口识别为资源，支持限流、熔断(blockHandler, blockHandlerClass)和异常(fallback, fallbackClass)的处理
    public RestTemplate getRestTemplate(){
        return new RestTemplate();
    }
}
